<template>
    <!-- 添加或修改生产订单和产品合计关联对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
               label-width="68px">
        <el-form-item label="采购方总部编码" prop="purchaserHqCode">
          <el-input v-model="queryParams.purchaserHqCode" placeholder="请输入采购方总部编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <!--<el-form-item label="供应商编码" prop="supplierCode">
            <el-input v-model="queryParams.supplierCode" placeholder="请输入供应商编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="供应商名称" prop="supplierName">
            <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>-->
        <el-form-item label="生产订单号" prop="ipoNo">
          <el-input v-model="queryParams.ipoNo" placeholder="请输入生产订单号"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <!--<el-form-item label="品类编码" prop="categoryCode">
            <el-input v-model="queryParams.categoryCode" placeholder="请输入品类编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>-->
        <el-form-item label="种类编码" prop="subclassCode">
          <el-input v-model="queryParams.subclassCode" placeholder="请输入种类编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="排产计划编码" prop="scheduleCode">
          <el-input v-model="queryParams.scheduleCode" placeholder="请输入排产计划编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <!--<el-form-item label="厂家物料编码" prop="materialsCode">
            <el-input v-model="queryParams.materialsCode" placeholder="请输入厂家物料编码"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="厂家物料名称" prop="materialsName">
            <el-input v-model="queryParams.materialsName" placeholder="请输入厂家物料名称"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="厂家物资单位" prop="materialsUnit">
            <el-input v-model="queryParams.materialsUnit" placeholder="请输入厂家物资单位"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="厂家物料描述" prop="materialsDesc">
            <el-input v-model="queryParams.materialsDesc" placeholder="请输入厂家物料描述"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="生产数量" prop="amount">
            <el-input v-model="queryParams.amount" placeholder="请输入生产数量"
                    clearable @keyup.enter.native="handleQuery"/>
        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                     v-hasPermi="['develop:FactoryProduceMain:add']">新增
          </el-button>
        </el-form-item>
      </el-form>

      <!--<el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                      v-hasPermi="['develop:FactoryProduceMain:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
              <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                      @click="handleUpdate" v-hasPermi="['develop:FactoryProduceMain:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
              <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                  <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                             v-hasPermi="['develop:FactoryProduceMain:remove']">删除</el-button>
              </el-popconfirm>
          </el-col>
          <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini"
                      @click="handleExport" v-hasPermi="['develop:FactoryProduceMain:export']">导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>-->

      <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
                :max-height="tableMaxHeight">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="生产订单号" width="150" align="center" prop="ipoNo">
          <template slot-scope="scope">
            <router-link class="link-type" to="">
              <span>{{ scope.row.ipoNo }}</span>
            </router-link>
          </template>
        </el-table-column>
        <el-table-column label="销售订单行项目号" width="150" align="center" prop="soItemNo"/>
        <el-table-column label="采购方总部编码" width="150" align="center" prop="purchaserHqCode"/>
        <el-table-column label="订单类型" width="150" align="center" prop="ipoType"/>
        <!--<el-table-column label="供应商编码" align="center" prop="supplierCode"/>
        <el-table-column label="供应商名称" align="center" prop="supplierName"/>-->
        <el-table-column label="品类编码" width="150" align="center" prop="categoryCode"/>
        <!--<el-table-column label="种类编码" align="center" prop="subclassCode"/>-->
        <el-table-column label="排产计划编码" width="150" align="center" prop="scheduleCode"/>
        <!--<el-table-column label="数据关联类型" align="center" prop="dataType"/>-->
        <!-- <el-table-column label="厂家物料编码" width="150" align="center" prop="materialsCode"/>
         <el-table-column label="厂家物料名称" width="150" align="center" prop="materialsName"/>
         <el-table-column label="厂家物资单位" width="150" align="center" prop="materialsUnit"/>
         <el-table-column label="厂家物料描述" width="150" align="center" prop="materialsDesc"/>-->
        <el-table-column label="生产数量" width="150" align="center" prop="amount"/>
        <el-table-column label="计量单位" width="150" align="center" prop="unit"/>
        <el-table-column label="产品型号" width="150" align="center" prop="productModel"/>

        <el-table-column label="计划开始日期" align="center" prop="planStartDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.planStartDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="计划完成日期" align="center" prop="planFinishDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.planFinishDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际开始日期" align="center" prop="actualStartDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.actualStartDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际完成日期" align="center" prop="actualFinishDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.actualFinishDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <!--<el-table-column label="计划开始日期" width="150" align="center" prop="planStartDate"/>
        <el-table-column label="计划完成日期" width="150" align="center" prop="planFinishDate"/>
        <el-table-column label="实际开始日期" width="150" align="center" prop="actualStartDate"/>
        <el-table-column label="实际完成日期" width="150" align="center" prop="actualFinishDate"/>-->
        <el-table-column label="生产工厂名称" width="150" align="center" prop="plantName"/>
        <el-table-column label="生产车间名称" width="150" align="center" prop="workshopName"/>
        <el-table-column label="生产订单状态" width="150" align="center" prop="ipoStatus"/>
        <el-table-column label="生产中心" width="150" align="center" prop="center"/>
        <!--<el-table-column label="数据来源" align="center" prop="dataSource"/>
        <el-table-column label="来源数据创建时间" align="center" prop="dataSourceCreateTime"/>
        <el-table-column label="数据拥有方" align="center" prop="ownerId"/>
        <el-table-column label="数据可见方" align="center" prop="openId"/>-->
        <el-table-column label="备注" align="center" width="300" prop="remark"/>
        <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
        <el-table-column label="操作" align="center" width="150" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button @click="goodsAll(scope.row)" icon="el-icon-reading" size="mini" type="text">
              详情
            </el-button>
            <!--<el-button @click="modifyGoodsAll(scope.row)" icon="el-icon-reading" size="mini" type="text">
              变更记录
            </el-button>-->
            <el-button @click="shengchangongdan(scope.row)" icon="el-icon-reading" size="mini" type="text">
              生产工单
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-edit"
                       @click="handleUpdate(scope.row)" v-hasPermi="['develop:FactoryProduceMain:edit']">修改
            </el-button>
            <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                           style="margin-left: 10px;">
              <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                         v-hasPermi="['develop:FactoryProduceMain:remove']">删除
              </el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @pagination="getList"/>

      <factoryProduceMain-form ref="form" @ok="getList"></factoryProduceMain-form>
      <shengchangongdanForm-List ref="shengchangongdanForm"></shengchangongdanForm-List>
      <goodsAllForm-List ref="goodsAllForm"></goodsAllForm-List>
      <modifyGoodsAllForm-List ref="modifyGoodsAllForm"></modifyGoodsAllForm-List>
    </el-dialog>
</template>

<script>
    import { deleteAction, getById, getAction } from '@/api/manage';
    import moment from 'moment';
    import FactoryProduceMainForm from '@/views/develop/factory/factoryProduceMain/module/FactoryProduceMainForm'
    import ShengchangongdanFormList from "@/views/develop/factory/factoryProduceWork/ShengchangongdanFormList.vue";
    import GoodsAllFormList from "@/views/develop/factory/factoryProduceMain/GoodsAllFormList.vue";

    export default {
        name: "DingdanFormList",
      components: {
        FactoryProduceMainForm,
        ShengchangongdanFormList,
        GoodsAllFormList,
      },
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 生产订单和产品合计关联表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                  pageNum: 1,
                  pageSize: 10,
                  status: null,
                  purchaserHqCode: null,
                  ipoType: null,
                  supplierCode: null,
                  supplierName: null,
                  ipoNo: null,
                 /* categoryCode: "60",
                  subclassCode: "60004",*/
                  scheduleCode: null,
                  poItemId: null,
                  dataType: null,
                  soItemNo: null,
                  materialsCode: null,
                  materialsName: null,
                  materialsUnit: null,
                  materialsDesc: null,
                  amount: null,
                  unit: null,
                  productIdGrpNo: null,
                  productIdType: null,
                  productModel: null,
                  planStartDate: null,
                  planFinishDate: null,
                  actualStartDate: null,
                  actualFinishDate: null,
                  plantName: null,
                  workshopName: null,
                  ipoStatus: null,
                  center: null,
                  dataSource: null,
                  dataSourceCreateTime: null,
                  ownerId: null,
                  openId: null,
                  projectId: null,
                  projectCode: null,
                },
                url: {
                  list: '/factoryProduceMain/factoryProduceMain/list',
                  remove: '/factoryProduceMain/factoryProduceMain/',
                  export: '/factoryProduceMain/factoryProduceMain/export',
                },
            };
        },
        created() {
        },
        methods: {
          goodsAll(row){
            this.$refs.goodsAllForm.show(row);
          },
          modifyGoodsAll(row){
            this.$refs.modifyGoodsAllForm.show(row);
          },
          shengchangongdan(row){
            this.$refs.shengchangongdanForm.show(row);
          },

          /** 删除按钮操作 */
          handleDelete(row) {
            const ids = row.id || this.ids;
            deleteAction(this.url.remove, ids).then(response => {
              this.getList();
              this.$modal.msgSuccess("删除成功");
            }).catch(() => {});
          },
          /** 修改按钮操作 */
          handleUpdate(row) {
            this.$refs.form.handleUpdate(row);
          },
          show(row) {
            this.queryParams.scheduleCode = row.scheduleCode;
            this.open = true;
            this.title = "生产产品信息";
            this.getList();
          },
          /** 查询生产订单和产品合计关联列表 */
          getList() {
            this.loading = true;
            getAction(this.url.list, this.queryParams).then(response => {
              this.dataList = response.rows;
              this.total = response.total;
              this.loading = false;
            });
          },
          handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
          },
          /** 重置按钮操作 */
          resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
          },
          // 多选框选中数据
          handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
          },
        }
    };
</script>
